package ui20131001.helper
{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;

	public class LoadFileCommand
	{
		private var _newsLoader:URLLoader;
		private var _gonggaoLoader:URLLoader;
		
		public function LoadFileCommand()
		{
		}
		
		public function loadFiles():void
		{
			var request:URLRequest;
			
			request = new URLRequest('http://cp.110cws.com/flash/news.xml');
			_newsLoader = new URLLoader();
			_newsLoader.dataFormat = URLLoaderDataFormat.TEXT;
			_newsLoader.addEventListener(Event.COMPLETE, loadComplete);
			_newsLoader.addEventListener(IOErrorEvent.IO_ERROR, loadError);
			_newsLoader.load(request);
			
			request = new URLRequest('http://cp.110cws.com/flash/gonggao.xml');
			_gonggaoLoader = new URLLoader();
			_gonggaoLoader.dataFormat = URLLoaderDataFormat.TEXT;
			_gonggaoLoader.addEventListener(Event.COMPLETE, loadComplete);
			_gonggaoLoader.addEventListener(IOErrorEvent.IO_ERROR, loadError);
			_gonggaoLoader.load(request);
		}
		
		private function loadComplete(e:Event):void
		{
			var loader:URLLoader = URLLoader(e.target);
			var xml:XML;
			var str:String = '';
			var news:XML, newStr:String, newsList:XMLList;
			if(loader==_newsLoader)
			{
				xml = XML(loader.data);
				newsList = xml.news;
				for each(news in newsList)
				{
					newStr = '<a href="'+news.@href+'" target="'+news.@target+'">'+news.title+'</a>';
					str += newStr+'<br>';
				}
				Global.newsHtmlStr = str;
			}else if(loader==_gonggaoLoader)
			{
				xml = XML(loader.data);
				newsList = xml.news;
				var content:String = '';
				for each(news in newsList)
				{
					content = news.title+'<br>'+news.child('text');
					newStr = '<a href="'+news.@href+'" target="'+news.@target+'">'+content+'</a>';
					str += newStr;
				}
				Global.gonggaoHtmlStr = str;
			}
			IndividualUsersController.getInst().updateAnnText();
		}
		
		private function loadError(e:IOErrorEvent):void
		{
			trace("LoadFileCommand error!!!" + e.text) ;
		}
		
	}
}